package com.xr.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xr.sunnyday.constant.MessageConstant;
import com.xr.sunnyday.entity.Result;
import com.xr.sunnyday.pojo.Setmeal;
import com.xr.sunnyday.service.SetMealService;
import com.xr.sunnyday.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setMeal")
public class SetmealMobileController {

    @Reference
    private SetMealService setMealService;

    @PostMapping("/getSetMeal")
    public Result getSetMeal(){
        List<Setmeal> setmealList=setMealService.findAll();
        setmealList.forEach(s->{
            s.setImg(QiNiuUtils.DOMAIN+s.getImg());
        });
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
    }

    @PostMapping("/findDetailById")
    public Result findDetailById(int id){
        Setmeal setmeal= setMealService.findDetailById(id);
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }

    @PostMapping("/findById")
    public Result findById(int id){
        // 根据id查询套餐
        Setmeal setmeal = setMealService.findBySetMealId(id);
        // 后台设置套餐图片显示路径
        setmeal.setImg(QiNiuUtils.DOMAIN+setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}
